package 蓝桥._2024.商品库存管理;

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt(); // 商品数量
        int m = scan.nextInt(); // 操作数量

        int[][] op = new int[m][2];
        for (int i = 0; i < m; i++) {
            op[i][0] = scan.nextInt() - 1 ;
            op[i][1] = scan.nextInt() - 1 ;
        }

        // 区间加法：使用差分数组
        int[] diff = new int[n+1];
        for (int i = 0; i < m; i++) {
            diff[op[i][0]] ++;
            diff[op[i][1]+1] --;
        }

        int[] stock = new int[n];
        stock[0] = diff[0];
        for (int i = 1; i < n; i++) {
            stock[i] = stock[i-1] + diff[i];
        }

        int[] ans = new int[m];
        for (int i = 0; i < m; i++) {
            int t = 0;
            for(int j = op[i][0]; j <= op[i][1]; j++) {
                if(stock[j] <= 1) {
                    t++;
                }
            }
            ans[i] = t;
        }

        for (int i = 0; i < m; i++) {
            System.out.println(ans[i]);
        }

        scan.close();
    }
}